﻿<?php
 GLOBAL $CFG;
require_once('../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/local/myplugin/lib.php');
require_once($CFG->dirroot . "/local/myplugin/forms.php");
$path = '/local/myplugin/';
global $DB;


/* Ket noi den file javascript - module.js */
$PAGE->requires->js_init_call('M.local_myplugin');	
$mycss =  $CFG->wwwroot.'/local/myplugin/css/mycss.css';

 echo '<link rel="stylesheet" href="'.$mycss.'" type="text/css" media="screen" />';

/* Chuan bi trang web can hien thi */	
$url = new moodle_url($CFG->wwwroot.'local/myplugin/modify_subject.php');
$PAGE->set_url($url);
$PAGE->set_title('Add Block of Knowledge');
$PAGE->set_heading('Add Block of Knowledge');
$PAGE->set_pagelayout('standard');

//Them thanh menu ngang ung voi trang trong duong link
navigation_node::override_active_url(new moodle_url($CFG->wwwroot.'/local/myplugin/modify_subject.php', array('param'=>'value')));
// $program_id = "";
// $block_id = "";
// if($_GET['program'] != "") {
	// $program_id = $_GET['program'];
	// $block_id= $_GET['block'];
// }
// else {
	// $program_id = $_POST['program'];
	// $block_id= $_POST['block'];
// }
$program_id = required_param('program', PARAM_TEXT);

echo $OUTPUT->header();

/* Viet doan code cua ban o day */

// //Lấy thông tin program
// $fromformdata['program'] = optional_param('program', $program_id, PARAM_TEXT);
 
// //Lấy thông tin  chuyên ngành đang áp dụng khối kiến thức
// //$major = $DB->get_records('major',array('program_id'=>$program_id));
// $sql = "SELECT * FROM mdl_major left join mdl_major_block on mdl_major.id = mdl_major_block.major_id ".
		// "WHERE mdl_major.program_id = ".$program_id;
// $major = $DB->get_records_sql($sql);

// foreach ($major as $r) {
	// if($r->blockofknowledge_id == $block_id) {
		// echo html_writer::tag('input',"&nbsp;".$r->major_name."&nbsp;&nbsp;&nbsp;", array('type'=>'checkbox','name'=>'major[]', 'value'=>$r->id, 'id'=>'chkmajor','checked'=>'checked')); 
	// }
	// else {
		// echo html_writer::tag('input',"&nbsp;".$r->major_name."&nbsp;&nbsp;&nbsp;", array('type'=>'checkbox','name'=>'major[]', 'value'=>$r->id, 'id'=>'chkmajor')); 
	// }
// }
// //Lấy thông tin block
// $block = $DB->get_record('block_of_knowledge', array('id'=>$block_id));
// $fromformdata['txtten'] = optional_param('txtten', $block->bok_name, PARAM_TEXT);
// $fromformdata['txttinchi'] = optional_param('txttinchi', $block->bok_credit, PARAM_TEXT);

$mform = new form_modify_subject(null, array('programid'=>$program_id));
$mform->display();

if($form_data=$mform->get_data())
{
	//Lấy danh sách các chuyên ngành
	$majors = array();
	$majors = $_POST['major'];
	//Lấy danh sách các môn học (nếu được chọn
	$subjects= array();
	$subjects=$_POST['selectedsubject'];
	
	
	$mylib = new curriculum_management();
	$mylib->update_block_knowledge($block_id, $program, $majors, $subjects);
	
}



//echo "<script  type='text/javascript'>get_all_subject_for_add_block();</script>";
echo $OUTPUT->footer();

